import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class SyMyGridView extends StatelessWidget {
  final  List<Map<String,String>> list=[];
    SyMyGridView({super.key});
    void initData(){
      // "雇主需求","服务人员","上传线索","待定功能",
      // "视频面试","财税工具","法务支持","家政险工"
      list.add({"img":"assets/app/home1.png","name":"雇主需求"});
      list.add({"img":"assets/app/home2.png","name":"服务人员"});
      list.add({"img":"assets/app/home3.png","name":"上传线索"});
      list.add({"img":"assets/app/home4.png","name":"待定功能"});
      list.add({"img":"assets/app/home5.png","name":"视频面试"});
      list.add({"img":"assets/app/home6.png","name":"财税工具"});
      list.add({"img":"assets/app/home7.png","name":"法务支持"});
      list.add({"img":"assets/app/home8.png","name":"家政险工"});

    }

  @override
  Widget build(BuildContext context) {
      initData();
    return Container(
      width: double.infinity,
      child: GridView.builder(
        padding: const EdgeInsets.all(1),
        // 整体内边距
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 4, // 一行 3 个 item
          crossAxisSpacing: 5, // 横向间距
          mainAxisSpacing: 5, // 纵向间距
          childAspectRatio: 1, // 宽高比，<1 高的更多
        ),
        itemCount: list.length,
        // 总共 30 项
        scrollDirection: Axis.vertical,
        // 垂直滚动
        shrinkWrap: true,
        // ❗ 必须，防止无限高度
        physics: NeverScrollableScrollPhysics(),
        // ❗ 禁止自身滚动
        itemBuilder: (context, index) {
          Map<String,String> item=list[index];
          return Container(
            height: 40,
            alignment: Alignment.center,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(8),
            ),
            child: Stack(
               children: [
                 Align(
                   alignment: Alignment(0, -0.1),
                    child:  Image.asset(
                      item['img']!,
                      fit: BoxFit.cover,
                      height: 40,
                      width: 40,
                    )
                 ),
                 Align(
                   alignment: Alignment.bottomCenter,
                   child: Text("${item['name']}"),
                 )
               ],
            ),
          );
        },
      ),
    );
  }
}